package org.glut.cloud.repairManage.controller;

import org.glut.cloud.repairManage.entity.RepairPersonnel1;
import org.glut.cloud.repairManage.service.IRepairPersonnel1Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 维修人员表 前端控制器
 *
 * @author sanmingzhi
 * @since 2024-08-13 19:10
 */
@RestController
@RequestMapping("/repair-personnel1")
public class RepairPersonnel1Controller {
    @Autowired
    private IRepairPersonnel1Service repairPersonnel1Service;

    /**
     * 获取所有维修人员信息
     *
     * @return 维修人员列表
     */
    @GetMapping("/list")
    public ResponseEntity<List<RepairPersonnel1>> getAllRepairPersonnel() {
        List<RepairPersonnel1> personnelList = repairPersonnel1Service.list();
        return ResponseEntity.ok(personnelList);
    }
    /**
     * 更新所有维修人员的月任务量
     *
     * @return 操作结果
     */

    @PutMapping("/resetMonthlyTaskCount")
    public ResponseEntity<Boolean> resetMonthlyTaskCount() {
        List<RepairPersonnel1> personnelList = repairPersonnel1Service.list();
        for (RepairPersonnel1 personnel : personnelList) {
            // 更新总任务量和月任务量
            personnel.setTotalTaskCount(personnel.getTotalTaskCount() + personnel.getMonthlyTaskCount());
            personnel.setMonthlyTaskCount(0);
            repairPersonnel1Service.updateById(personnel);
        }
        return ResponseEntity.ok(true);
    }
}
